[ask][php] find dynamic filename exist

Posted by r4ccoon on Stack Overflow See other posts from Stack Overflow or by r4ccoon
Published on 2010-05-14T21:40:52Z Indexed on 2010/05/14 21:44 UTC
Read the original article Hit count: 155

Filed under:
|

hi. i am writing a cache module in php. it tries to write a cache with a $string+timestamp as a filename. i dont have problem with writing the cache.

the problem is i do a foreach loop to get the cache that i want.

this is the logic that i use for getting the cache

foreach ($filenames as $filename){ 
    if(strstr($filename,$cachename)){//if found 
        if(check_timestamp($filename,time()))
                          display_cace($filename);  
        break;
    } 
}

but when it tries to get and read the cache, it slows the server down. imagine that i have 10000 cache file in a folder, and i need to check for every file in that cache folder.

so how do you think the best way of doing this.

here i explain again, because even me still dont understand my written question.. :D

i write cache file with this format filename_timestamp.. e.g cache_function_random_news_191982899010 in a folder ./cache/

when i want to get the cache, i only pass "cache_function_random_news_" and check recursively on that folder. if i find something with that needle on a file name, display it, and break.

but checking recursively on a 10000 files in a folder is not a good thing yeah? please give me your opinion ok, that would clarify more. thanks.

© Stack Overflow or respective owner

Related posts about php5

Related posts about codeigniter